//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lujieni.springboothutool.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.extra.spring.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 数据脱敏类
 */
public class DataDesensitizationUtils {
    private static final Logger log = LoggerFactory.getLogger(DataDesensitizationUtils.class);

    private static AES aes = null;

    static {
        // AES要求密钥长度为128/192/256位
        String password = SpringUtil.getProperty("encryptor.password");
        // 创建 AES 加密器,线程安全
        aes = SecureUtil.aes(password.getBytes());
    }

    public static String decrypt(String value) {
        try {
            return value == null ? null : aes.decryptStr(value);
        } catch (Exception e) {
            log.error("ERROR method DataDesensitizationUtils.decrypt : {} ", e);
            return value;
        }
    }

    public static String encrypt(String rawValue) {
        try {
            // 加密（返回 Base64 字符串）
            return rawValue == null ? null : aes.encryptBase64(rawValue);
        } catch (Exception var2) {
            Exception e = var2;
            log.error("ERROR method DataDesensitizationUtils.encrypt : {} ", e);
            return rawValue;
        }
    }

}
